#include "taskQueue.h"

int queueInit(taskQueue_t *queue)
{
    bzero(queue,sizeof(taskQueue_t));
    pthread_mutex_init(&queue->mutex,NULL);
    pthread_cond_init(&queue->cond,NULL);

    return 0;
}

int enqueue(taskQueue_t *queue,int netfd)
{
    task_t *new_node = (task_t *)calloc(1,sizeof(task_t));
    new_node->netfd = netfd;

    if(queue->tail)
    {
        queue->tail->next = new_node;
        queue->tail = new_node;
    }
    else 
    {
        queue->head = new_node;
        queue->tail = new_node;
    }

    ++queue->queue_size;
}

int dequeue(taskQueue_t *queue)
{
    task_t *cur = queue->head;
    queue->head = queue->head->next;
    free(cur);

    --queue->queue_size;

    printf("dequeue\n");
    if(queue->queue_size == 0)
    {
        queue->tail = NULL;    
    }

    return 0;
}
